# -*- coding: utf-8 -*-

import random
import os
import sys
from PyQt5.QtCore import *
from PyQt5.QtSql import (QSqlDatabase, QSqlQuery, QSqlTableModel)
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import time
import datetime,math
def generate_verification_code():
    ''' 随机生成6位的验证码 '''
    code_list = []
    for i in range(10): # 0-9数字
        code_list.append(str(i))
    # for i in range(65, 91): # A-Z
    #     code_list.append(chr(i))
    for i in range(97, 123): # a-z
        code_list.append(chr(i))

    #print(code_list)
    myslice = random.sample(code_list, 6)  # 从list中随机获取6个元素，作为一个片断返回
    verification_code = ''.join(myslice) # list to string
    # print code_list
    # print type(myslice)
    return verification_code

def generate_verification_code2():
    ''' 随机生成6位的验证码 '''
    code_list = []
    for i in range(2):
        random_num = random.randint(0, 9) # 随机生成0-9的数字
        # 利用random.randint()函数生成一个随机整数a，使得65<=a<=90
        # 对应从“A”到“Z”的ASCII码
        a = random.randint(65, 90)
        b = random.randint(97, 122)
        random_uppercase_letter = chr(a)
        random_lowercase_letter = chr(b)

        code_list.append(str(random_num))
        code_list.append(random_uppercase_letter)
        code_list.append(random_lowercase_letter)
    verification_code = ''.join(code_list)
    return verification_code

if __name__ == '__main__':
    app = QApplication(sys.argv)
    filename = os.path.join(os.path.dirname(__file__), "reference.db")
    create = not QFile.exists(filename)

    db = QSqlDatabase.addDatabase("QSQLITE")
    db.setDatabaseName(filename)
    if not db.open():
        QMessageBox.warning(None, "Reference Data",
                            "Database Error: {0}".format(db.lastError().text()))
        sys.exit(1)
    query = QSqlQuery()
    for i in range(1, 100000):
        code = generate_verification_code()
        # code2 = generate_verification_code2()
        print(code)
        query.exec_("insert into sjm (sjmm)values('"+code+"')")

